package com.xs.ahoi.hcxs.utils;


import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池工具类
 *
 * @author: fuhuichao
 * @date: 2021/9/15 11:23 上午
 */
public class ThreadPoolFactory {

    protected static final Object LOCK = new Object();

    protected static ThreadPoolExecutor instance = null;

    private ThreadPoolFactory() {

    }

    /**
     * 单例获取线程池
     */
    public static ThreadPoolExecutor getInstance() {
        if (instance != null) {
            return instance;
        }

        synchronized (LOCK) {
            if (instance != null) {
                return instance;
            }

            instance = new ThreadPoolExecutor(
                    10,
                    10,
                    2000L,
                    TimeUnit.MILLISECONDS,
                    new LinkedBlockingQueue<>(1000));
            return instance;
        }
    }
}
